class Solution(object):
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        bits = [0] * 32
        sign = 0
        for num in nums:
            if num<0: sign+=1
            num = abs(num)
            s = bin(num)
            numb = list(bin(num)[2:])
            numb.reverse()
            for i, b in enumerate(numb):
                if b=='1': bits[i] += 1
        bits = [str(bit%3) for bit in bits]
        bits.reverse()
        digits = int(''.join(bits),base=2)
        sign = sign % 3
        return -digits if sign else digits

print(Solution().singleNumber([-2,-2,1,1,-3,1,-3,-3,-4,-2]))
